<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <!-- <script>
      console.log(1)
      setTimeout(() => {
        console.log(2)
      }, 2000)
      setTimeout(() => {
        console.log(3)
      }, 1000)
      console.log(4)
      // 1 4 3 2
    </script> -->
    <!-- <script>
      console.log(1)
      setTimeout(() => {
        console.log(2)
      })
      setTimeout(() => {
        console.log(3)
      })
      console.log(4)
      // 1 4 2 3
    </script> -->
    <!-- <script>
      setTimeout(function () {
        console.log(1)
      })
      new Promise(function (resolve, reject) {
        console.log(2)
        resolve(3)
      }).then(function (val) {
        console.log(val)
      })
      console.log(4)
      // 2 4 3 1
    </script> -->

    <script>
        console.log(1)

        setTimeout(function () {
            console.log(2)
            new Promise(function (resolve) {
                console.log(3)
                resolve()
            }).then(function () {
                console.log(4)
            })
        })

        const p = new Promise((resolve, reject) => {
            console.log(5)
            resolve() // 标记为成功
            console.log(6)
        })

        p.then((data) => {
            console.log(7)
        })

        console.log(8)
      //1 5 6 8 7 2 3 4
    </script>
</body>

</html>